<?php
/**
 * Login_Model_Login
 * main login model
 * manage login actions
 * 
 * @author Adrian Stolarski
 */
class Login_Model_Login implements Login_Model_Mainable, Login_Model_Selectable {
    
    /**
     *
     * @var type $helper_model
     * current helper model handler
     */
    public $helper_model;
    
    /**
     *
     * @var type $action
     * action handler
     */
    public $action;
    /**
     *
     * @var type action_loader
     * action loader handler
     */
    public $action_loader;
    
    /**
     * main()
     * initialise login action
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->action = $variables['get']['name'];
        if(isset($this->action) && (!is_null($this->action)) && (trim($this->action) != '')){
            $page = $this->select_action($variables);
            return $page;
        }
        else {
            $this->action_loader = new Core_Controller_Redirect;
            $this->action_loader->main($variables);
        }
    }

    public function select_action(array $variables = null) {
        switch($this->action){
            case 'login':
                return $this->login_action($variables);
                break;
            case 'logged':
                $this->logged_action($variables);
                break;
            case 'registry':
                return $this->registry_action($variables);
                break;
            case 'registred':
                $this->registred_action();
                break;
            case 'forgot':
                return $this->forgot_password($variables);
                break;
            case 'forgotten':
                $this->forgoten_password($variables);
                break;
            case 'facebook_login':
                break;
            case 'facebook_registry':
                break;
            case 'gmail_login':
                break;
            case 'gmail_registry':
                break;
            case 'twitter_login':
                break;
            case 'twitter_registry':
                break;
            default:
                $this->action_loader = new Core_Controller_Redirect;
                $this->action_loader->main($variables);
        }
        
    }
    
    private function forgoten_password(array $variables){
        
    }
    
    /**
     * forgot_password()
     * forgot password form data
     * 
     * @param array $variables
     * @return array $page
     */
    private function forgot_password(array $variables = null){
        $this->action_loader = new Login_Data_Forgot;
        return $this->action_loader->main($variables);
    }
    
    /**
     * registred_action()
     * registry user
     * 
     * @param array $variables
     */
    private function registred_action(array $variables = null){
        $this->action_loader = new Login_Data_Registred;
        $this->registred_action($variables);
    }
    
    /**
     * registry_action()
     * return registry form
     * 
     * @param array $variables
     * @return type $template
     */
    private function registry_action(array $variables = null){
        $this->action_loader = new Login_Data_Registry;
        return $this->action_loader->main($variables);
    }
    
    /**
     * logged_action()
     * logged implementation handler
     * 
     * @param array $variables
     */
    private function logged_action(array $variables = null){
        $this->action_loader = new Login_Model_Logged;
        $this->action_loader->main($variables);
    }
    
    /**
     * login_action()
     * return login template
     * @param array $variables
     * @return type $template
     */
    private function login_action(array $variables = null){
        $this->action_loader = new Login_Data_Login;
        return $this->action_loader->main($variables);
    }

}
